package com.example.multi.token.provider.controller;

import com.example.multi.token.provider.model.TokenInfo;
import com.example.multi.token.provider.service.ITokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author
 * @description
 * @create 2022-05-20 11:35
 */
@Controller
@RequestMapping("")
public class TokenController {

    @Autowired
    private ITokenService tokenService;

    @RequestMapping(value = {"", "/"}, method = RequestMethod.GET)
    @ResponseBody
    public Object getToken() {
        Map<String, Object> result = new ConcurrentHashMap<>();
        TokenInfo ti = tokenService.getToken();
        ResponseEntity responseEntity = ResponseEntity.ok().body(ti);
        Mono<ResponseEntity> mono = Mono.just(responseEntity).cache(Duration.ofSeconds(5));
        return mono;
    }
}
